package org.sith.taskrunner.ejb.transformers;

import org.sith.taskrunner.api.transformer.InputDataTransofrmer;
import org.sith.taskrunner.api.exceptions.TransformInputDataException;
import org.sith.taskrunner.ejb.tasks.SumInputData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Transform XML to SumInputDate
 * 
 *
 * @param inputDate
 * @return SumInputDate
 * @throws TransformInputDataException
 * 
 */

public class StringXmlTransformer extends AbstractNormalAndSumXMLDataTransformer implements
		InputDataTransofrmer<SumInputData, InputStream> {

	@Override
	public SumInputData transform(InputStream inputData)
			throws TransformInputDataException {
		List<Double> numerics = getResultSequence(inputData);
		List<Integer> numericsInteger = new ArrayList<Integer>();
		for( int i = 0 ; i<numerics.size(); i++){
			double d = numerics.get(i);
			numericsInteger.add(new Integer((int) d));
		}
		
		return new SumInputData(numericsInteger);
	}

}
